//
//  CollectionCellForImage.m
//  MY Project For Sport
//
//  Created by dllo on 16/3/4.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CollectionCellForImage.h"
#import "ModelForImage.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <UMSocialQQHandler.h>
#import <UMSocialSinaSSOHandler.h>
#import <UMSocial.h>
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667

@interface CollectionCellForImage ()

@property (nonatomic, retain)UIImageView *viewForImage;
@property (nonatomic, retain)UILabel *labelForTitle;
@property (nonatomic, retain)NSString *height;
@property (nonatomic, retain)UIButton *share;
//@property (nonatomic, retain)UILabel *labelForCurren;
//@property (nonatomic, retain)UILabel *labelForCount;
@property (nonatomic, retain)NSString *image;

@end

@implementation CollectionCellForImage

-(void)dealloc {
    
    [_viewForImage release];
    [_labelForTitle release];
    [_labelForIntro release];
    [_labelForName release];
    [_labelForCurren release];
    [_labelForCount release];
    [_blackView release];
    [_height release];
    [_share release];
    [_image release];
    [super dealloc];
    
}

-(instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    
    if (self) {
        
      //  self.contentView.backgroundColor = [UIColor greenColor];
        [self createSubview];
    }

    return self;
}

- (void)createSubview{

    self.viewForImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.viewForImage];
    [_viewForImage release];
    
    self.blackView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.blackView];
    [_blackView release];
    
    self.labelForTitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForTitle];
    [_labelForTitle release];
    
    self.labelForName = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForName];
    [_labelForName release];

    self.labelForIntro = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForIntro];
    [_labelForIntro release];
    
    self.labelForCurren = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForCurren];
    [_labelForCurren release];
    
    self.labelForCount = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForCount];
    [_labelForCount release];
    
    self.share = [UIButton buttonWithType:UIButtonTypeCustom];
       [self.contentView addSubview:self.share];
    //self.share.backgroundColor = [UIColor whiteColor];
    
    
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    
    self.viewForImage.frame = CGRectMake(5 * WEIGHTT, 5 * HEIGHTT, WIDTH - 10 * WEIGHTT ,HEIGHT - 10 * HEIGHTT);
    
    self.blackView.frame = CGRectMake(0, HEIGHT / 5 * 4, WIDTH, HEIGHT / 5);
    self.blackView.backgroundColor = [UIColor blackColor];
    self.blackView.alpha = 0.3;
    
    
    self.labelForName.frame = CGRectMake(15 * WEIGHTT, HEIGHT / 5 * 3 + HEIGHT / 5 + 5 * HEIGHTT, WIDTH - 30 * WEIGHTT, HEIGHT / 20);
    self.labelForName.textColor = [UIColor whiteColor];
    
    self.labelForTitle.frame = CGRectMake(15 * WEIGHTT, HEIGHT / 5 * 3 + HEIGHT / 5 + 5 * HEIGHTT+ HEIGHT / 20 + 10 * HEIGHTT, WIDTH / 3 * 2, HEIGHT / 25);
    self.labelForTitle.textColor = [UIColor whiteColor];
    
    
    self.labelForCurren.frame = CGRectMake(WIDTH / 3 * 2 + 35 * WEIGHTT , HEIGHT / 5 * 3 + HEIGHT / 5  + HEIGHT / 20 + 15 * HEIGHTT , WIDTH / 15, HEIGHT / 25);
    self.labelForCurren.textColor = [UIColor whiteColor];
    self.labelForCurren.textAlignment = NSTextAlignmentCenter;
    
    self.labelForCount.frame = CGRectMake(WIDTH / 3 * 2  + WIDTH / 15 + 40 * WEIGHTT , HEIGHT / 5 * 3 + HEIGHT / 5  + HEIGHT / 20 + 15 * HEIGHTT, WIDTH / 11, HEIGHT / 25);
    self.labelForCount.textColor = [UIColor whiteColor];
    
    self.labelForIntro.frame = CGRectMake(15 * WEIGHTT, HEIGHT / 5 * 3 + HEIGHT / 5  + HEIGHT / 20 + 15 * HEIGHTT + HEIGHT / 25  , WIDTH - 30 * WEIGHTT, HEIGHT / 15);
    self.labelForIntro.numberOfLines = 0;
    self.labelForIntro.font = [UIFont systemFontOfSize:13];
    self.labelForIntro.textColor = [UIColor whiteColor];
    
    self.share.frame = CGRectMake(WIDTH - WIDTH / 9 - 5 * WEIGHTT, 20 * HEIGHTT, WIDTH / 9, 44);
    [self.share setImage:[UIImage imageNamed:@"iconfont-share"] forState:UIControlStateNormal];
    


}

- (void)passModelForImage:(ModelForImage *)model {
    
    self.labelForTitle.text = model.title;
    self.labelForIntro.text = model.intro;
    [self.viewForImage sd_setImageWithURL:[NSURL URLWithString:model.img_url]];
    
    [self.share addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
    self.image = model.img_url;

    
}


/**分享点击事件*/
- (void)shareAction:(UIButton *) button {
    
    
    // 横屏分享
    
    // [UMSocialConfig setSupportedInterfaceOrientations:UIInterfaceOrientationMaskLandscape];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"share" object:nil userInfo:@{@"image":self.image}];
    
    
}


@end
